#ifndef sPHENIX_ROOT_MANAGER_H
#define sPHENIX_ROOT_MANAGER_H

#include <TObject.h>
#include <TTree.h>
#include <TFile.h>
#include <TDirectory.h>
 
class TParticle;
class TCanvas;
class TH1D;
class TH2D;
class TH3D;

/// Root file mode
enum FileMode { 
  kRead,  ///< Read mode 
  kWrite  ///< Write mode
};
 
/// \ingroup E02
/// \brief Class that takes care of Root IO
///
/// Geant4 novice ExampleN02 adapted to Virtual Monte Carlo 
///
/// \date 05/04/2002
/// \author I. Hrivnacova; IPN, Orsay
 
#include "sPHENIX_DetectorConstruction.h"
#include "sPHENIX_EMCalSD.h"
#include "sPHENIX_PreshowerSD.h"
#include "sPHENIX_HCalSD.h"

class sPHENIX_RootManager : public TObject
{
 public:
  sPHENIX_RootManager(const char* projectName, 
		      FileMode fileMode);
  sPHENIX_RootManager();
  virtual ~sPHENIX_RootManager();     
  
  // static access method
  static sPHENIX_RootManager* Instance(); 
 
  // methods
  void  Register(const char* name, const char* className, void* objAddress);
  void  Fill();
  void  WriteAll();
  void  ReadEvent(Int_t i);
 
  void  InitializeHistograms();
  void  RunAnalysis();

  // set
  void SetDetectorConstruction(sPHENIX_DetectorConstruction* detector)
  { Detector = detector;}

  void SetEMCalSD(sPHENIX_EMCalSD* emcalsd)
  { EMCalSD = emcalsd;}

  void SetPreshowerSD(sPHENIX_PreshowerSD* preshowersd)
  { PreshowerSD = preshowersd;}

  void SetHCalSD(sPHENIX_HCalSD* hcalsd)
  { HCalSD = hcalsd;}
  
  void SetNofEvents(Int_t nOfEvents)
  { NofEvents = nOfEvents;}

 private:
  // data members 
  static  sPHENIX_RootManager* gInstance; ///< Singleton instance
 
  // data members
  TFile*  File; ///< Root output file
  TTree*  Tree; ///< Root output tree 
  TString Path; ///< The path to the root file

  sPHENIX_DetectorConstruction* Detector;
  sPHENIX_EMCalSD*              EMCalSD;
  sPHENIX_PreshowerSD*          PreshowerSD;
  sPHENIX_HCalSD*               HCalSD;

  TCanvas* c2;
  TH2D* hEtotTowerEMCal;
  TH1D* hNumberEventsByEnergyEMCal;
  TH2D* hEtotTowerPreshower;
  TH1D* hNumberEventsByEnergyPreshower;
  TH2D* hEtotTowerHCal;
  TH1D* hNumberEventsByEnergyHCal;
  
     
  Int_t NofEvents;
  Int_t count;

  ClassDef(sPHENIX_RootManager,0); // Root IO manager
};
 
#endif //sPHENIX_ROOT_MANAGER_H  
